<?php

namespace App\Containers\AppSection\Project\Tasks;

use App\Containers\AppSection\Project\Data\Repositories\DocumentRepository;
use App\Ship\Criterias\ThisProjectCriteria;
use App\Ship\Parents\Tasks\Task;

class GetDocumentsTask extends Task
{
    protected DocumentRepository $repository;

    public function __construct(DocumentRepository $repository)
    {
        $this->repository = $repository;
    }

    public function run()
    {
        return $this->repository->paginate();
    }

    public function thisProject($projectId): self
    {
        $this->repository->pushCriteria(new ThisProjectCriteria($projectId));
        return $this;
    }

    public function required($required = true): self
    {
        $this->repository->findWhere(['required' => $required]);
        return $this;
    }
}
